package com.nondo.rdp.finance.endpoint.api.app;

import com.nondo.rdp.auth.service.UserService;
import com.nondo.rdp.core.model.View;
import com.nondo.rdp.finance.domain.Article;
import com.nondo.rdp.finance.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController("apiAppArticle")
@RequestMapping("/api/app/article")
public class ArticleEndpoint {
    @Autowired
    ArticleService articleService;

    @Autowired
    UserService userService;

    @RequestMapping("/info/{id}")
    public View info(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id) {
        View view = new View(20000, "获取数据成功");

        Article article = new Article();
        if (id != null) {
            article = articleService.findOne(id);
        }

        view.setData(article);
        return view;
    }

    @RequestMapping("/type/{type}")
    public View info(HttpServletRequest request, HttpServletResponse response, @PathVariable("type") String type) {
        View view = new View(20000, "获取数据成功");

        Article article = new Article();
        if (type != null) {
            article = articleService.findByType(type);
        }

        view.setData(article);
        return view;
    }
}